package com.beta.mq.redis.model;

import com.alibaba.fastjson.JSON;
import com.beta.mq.redis.producer.annotation.ToQueue;
import lombok.Data;

import java.io.Serializable;

/**
 * @author taofucheng
 * @date 2015/12/9.
 */
@Data
public class Message implements Serializable {

    private Object content;

    private long expireAt;

    /**
     * 已经重试的次数
     */
    private int tryTimes = 0;

    public Message(Object content, long expireAt) {
        this.content = content;
        this.expireAt = expireAt;
    }

    public Message(Object content) {
        this(content, ToQueue.ExpireTime.NEVER_EXPIRES);
    }

    public <T> T getContent(Class<T> entityClass) {
        if (content == null || entityClass == null) {
            return null;
        }
        return JSON.parseObject(JSON.toJSONString(content), entityClass);
    }

}

